<?php

namespace App\Http\Controllers\Admin\Polity;

use App\Http\Requests\ChoiceRequest;
use App\Models\PolityChoices;
use App\Http\Controllers\Controller;

class ChoiceController extends Controller
{
    public function index()
    {
        $data = PolityChoices::orderBy('id', 'desc')->paginate(10);
        return view('admin.polity.choice.index', ['data' => $data]);
    }

    public function create()
    {
        $data = new PolityChoices();
        return view('admin.polity.choice.create', ['data' => $data]);
    }

    public function store(ChoiceRequest $request)
    {
        PolityChoices::create($request->all());
        return redirect('admin/polity/choice')->with('msg', '添加成功！');
    }

    public function edit($id)
    {
        $data = PolityChoices::findOrFail($id);
        return view('admin.polity.choice.edit', ['data' => $data]);
    }

    public function update(ChoiceRequest $request, $id)
    {
        $data = PolityChoices::findOrFail($id);
        $data->update($request->all());
        return redirect('admin/polity/choice')->with('msg', '修改成功！');
    }

    public function destroy($id)
    {
        PolityChoices::destroy($id);
        return redirect('admin/polity/choice')->with('msg', '删除成功！');
    }
}
